package com.rds.web.controller.pms;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rds.common.annotation.Log;
import com.rds.common.enums.BusinessType;
import com.rds.system.domain.RdaTreemenu;
import com.rds.system.service.IRdaTreemenuService;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.common.core.page.TableDataInfo;

/**
 * 树菜单Controller
 *
 * @author rds
 * @date 2021-05-27
 */
@RestController
@RequestMapping("/pms/treemenu")
public class RdaTreemenuController extends BaseController
{
    @Autowired
    private IRdaTreemenuService rdaTreemenuService;

    /**
     * 查询树菜单列表
     */
//    @PreAuthorize("@ss.hasPermi('pms:treemenu:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaTreemenu rdaTreemenu)
    {
        startPage();
        List<RdaTreemenu> list = rdaTreemenuService.selectRdaTreemenuList(rdaTreemenu);
        return getDataTable(list);
    }

    /**
     * 导出树菜单列表
     */
    @PreAuthorize("@ss.hasPermi('pms:treemenu:export')")
    @Log(title = "树菜单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaTreemenu rdaTreemenu)
    {
        List<RdaTreemenu> list = rdaTreemenuService.selectRdaTreemenuList(rdaTreemenu);
        ExcelUtil<RdaTreemenu> util = new ExcelUtil<RdaTreemenu>(RdaTreemenu.class);
        return util.exportExcel(list, "treemenu");
    }

    /**
     * 获取树菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:treemenu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaTreemenuService.selectRdaTreemenuById(id));
    }

    /**
     * 新增树菜单
     */
    @PreAuthorize("@ss.hasPermi('pms:treemenu:add')")
    @Log(title = "树菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaTreemenu rdaTreemenu)
    {
        return toAjax(rdaTreemenuService.insertRdaTreemenu(rdaTreemenu));
    }

    /**
     * 修改树菜单
     */
    @PreAuthorize("@ss.hasPermi('pms:treemenu:edit')")
    @Log(title = "树菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaTreemenu rdaTreemenu)
    {
        return toAjax(rdaTreemenuService.updateRdaTreemenu(rdaTreemenu));
    }

    /**
     * 删除树菜单
     */
    @PreAuthorize("@ss.hasPermi('pms:treemenu:remove')")
    @Log(title = "树菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaTreemenuService.deleteRdaTreemenuByIds(ids));
    }
}
